package me.zhengjie.modules.workorder.rest;

import me.zhengjie.aop.log.Log;
import me.zhengjie.modules.workorder.domain.TWorkOrderLog;
import me.zhengjie.modules.workorder.service.TWorkOrderLogService;
import me.zhengjie.modules.workorder.service.dto.TWorkOrderLogQueryCriteria;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


/**
* @author zcw
* @date 2019-11-03
*/
@RestController
@RequestMapping("api")
public class TWorkOrderLogController {

    @Autowired
    private TWorkOrderLogService tWorkOrderLogService;

    @Log("查询TWorkOrderLog")
    @GetMapping(value = "/tWorkOrderLog")
    @PreAuthorize("hasAnyRole('ADMIN','TWORKORDERLOG_ALL','TWORKORDERLOG_SELECT')")
    public ResponseEntity getTWorkOrderLogs(TWorkOrderLogQueryCriteria criteria, Pageable pageable){
        return new ResponseEntity(tWorkOrderLogService.queryAll(criteria,pageable),HttpStatus.OK);
    }

    @Log("新增TWorkOrderLog")
    @PostMapping(value = "/tWorkOrderLog")
    @PreAuthorize("hasAnyRole('ADMIN','TWORKORDERLOG_ALL','TWORKORDERLOG_CREATE')")
    public ResponseEntity create(@Validated @RequestBody TWorkOrderLog resources){
        return new ResponseEntity(tWorkOrderLogService.create(resources),HttpStatus.CREATED);
    }

    @Log("修改TWorkOrderLog")
    @PutMapping(value = "/tWorkOrderLog")
    @PreAuthorize("hasAnyRole('ADMIN','TWORKORDERLOG_ALL','TWORKORDERLOG_EDIT')")
    public ResponseEntity update(@Validated @RequestBody TWorkOrderLog resources){
        tWorkOrderLogService.update(resources);
        return new ResponseEntity(HttpStatus.NO_CONTENT);
    }

    @Log("删除TWorkOrderLog")
    @DeleteMapping(value = "/tWorkOrderLog/{id}")
    @PreAuthorize("hasAnyRole('ADMIN','TWORKORDERLOG_ALL','TWORKORDERLOG_DELETE')")
    public ResponseEntity delete(@PathVariable Long id){
        tWorkOrderLogService.delete(id);
        return new ResponseEntity(HttpStatus.OK);
    }
}